layui.use(['table','form','laydate','laytpl','element'], function() {
	var table = layui.table;
	var form = layui.form,
    laydate = layui.laydate,
    laytpl = layui.laytpl,
    element = layui.element;
    
	/*测评时间动态加载*/
	$.ajax({
		type : 'get',
		url : '../sysunifiedmanagement/getperiod',
		datatype : 'json',
		success : function(timedate) {
			if (timedate.code == 10001) {
				var str = "";
				for(var i = 0; i < timedate.count; i++){
					str += '<option value=' + timedate.data[i].starTime+"/"+timedate.data[i].endTime + '>'+ timedate.data[i].starTime+'/'+timedate.data[i].endTime+'</option>';
				}
				$("#selchecktime").append(str);
				form.render("select");
			}
			else{
				layer.msg("测试时间获取失败");
			}
		}
	});
	
	/*动态加载测试报告类型下拉框*/
	$.ajax({
		type : 'get',
		url : '../json/testReportType.json',
		datatype : 'json',
		success : function(typedate) {
			if (typedate.code == 0) {
				var str = "";
				for(var i = 0; i < typedate.count; i++){
					str += '<option value=' + typedate.data[i].name + '>'+ typedate.data[i].name+'</option>';
				}
				$("#testreporttype").append(str);
				form.render("select");
			}
			else{
				layer.msg("测试报告类型获取失败");
			}
		}
	});
	
	form.on('select(selgradename)', function(data) {
		var grade=data.value;
		var schoolid = $("#selschool").val();
		if(schoolid == 00){
			schoolid ="";
		}
		/*动态加载班级下拉框*/
		$("#classid").html("");
		$.ajax({
			type : 'get',
			url : '../sysclassmanagement/getclassbygrade?grade='+grade+'&schoolid='+schoolid,
			datatype : 'json',
			success : function(classdate) {
				if (classdate.code == 0) {
					var str = "<option value='00'>请选择班级</option>";
					for(var i = 0; i < classdate.count; i++){
						str += '<option value=' + classdate.data[i].classid + '>'+ classdate.data[i].className +'</option>';
					}
					$("#classid").append(str);
					form.render("select");
				}
				else{
					$("#classid").html("");
					layer.msg('暂无对应的班级', {icon: 2});
					form.render("select");
				}
			}
		});
	});
    
    form.on('select(testreporttype)', function(data) {
		var reporttype = data.value;
		table.render({
			elem: '#ownness',
			url: '../sysperevaluation/getperevaselect?reporttype='+reporttype,
			title: '个人测评结果数据表',
			height: "full-155",
			skin: 'line',
			even: true,
			cols: [
				[{
					type: 'numbers',
					title: '序号',
					align: 'center',
					width: '5%'
				},{
					field: 'username',
					title: '用户号',
					align: 'center',
					width: '12%'
				}, {
					field: 'realName',
					title: '学生姓名',
					align: 'center',
					width: '10%'
				}, {
					field: 'sex',
					title: '性别',
					align: 'center',
					width: '6%'
				}, {
					field: 'checkname',
					title: '评测类型名称',
					align: 'center',
					width: '25%'
				}, {
					field: 'grade',
					title: '年级',
					align: 'center',
					width: '10%'
				}, {
					field: 'className',
					title: '班级',
					align: 'center',
					width: '7%'
				},  {
					field: 'checktime',
					title: '测评时间',
					align: 'center',
					width: '10%'
				}, {
					title: '操作',
					toolbar: '#barDemo',
					align: 'center',
					width: '15%'
				}]
			],page: {
				layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
				groups: 5,
				limit: 10,
				limits: [10, 20, 30, 40, 50],
				theme: '#1E9FFF',					
			}
		});
    });
    
    $("#btnselperevalua").click(function(){
    	var checktime=$("#selchecktime").val();
		var reporttype = $("#testreporttype").val();
    	var schoolid = $("#selschool").val();
    	var classid=$("#classid").val();
		var stuid = $("#inpstuid").val();
		if(checktime==00){
			checktime="";
		}
		if(reporttype==00){
			reporttype="";
		}
		if(schoolid==00){
			schoolid="";
		}
		if(classid==00 || classid==null){
			classid="";
		}
		table.render({
			elem: '#ownness',
			url: '../sysperevaluation/getperevaselect?checktime='+checktime+'&reporttype='+reporttype+'&classid='+classid+'&stuid='+stuid+'&schoolid='+schoolid,
			title: '个人测评结果数据表',
			height: "full-155",
			skin: 'line',
			even: true,
			cols: [
				[{
					type: 'numbers',
					title: '序号',
					align: 'center',
					width: '5%'
				},{
					field: 'username',
					title: '用户号',
					align: 'center',
					width: '12%'
				}, {
					field: 'realName',
					title: '学生姓名',
					align: 'center',
					width: '10%'
				}, {
					field: 'sex',
					title: '性别',
					align: 'center',
					width: '6%'
				}, {
					field: 'checkname',
					title: '评测类型名称',
					align: 'center',
					width: '25%'
				}, {
					field: 'grade',
					title: '年级',
					align: 'center',
					width: '10%'
				}, {
					field: 'className',
					title: '班级',
					align: 'center',
					width: '7%'
				},  {
					field: 'checktime',
					title: '测评时间',
					align: 'center',
					width: '10%'
				}, {
					title: '操作',
					toolbar: '#barDemo',
					align: 'center',
					width: '15%'
				}]
			],page: {
				layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
				groups: 5,
				limit: 10,
				limits: [10, 20, 30, 40, 50],
				theme: '#1E9FFF',					
			}
		});
		
    });
    
    
    table.on('tool(ownness)', function(obj){
	    var checkdata = obj.data;
	    if(obj.event === 'result1'){
	    	var index = layer.open({
				type: 2, 
			    title: '《中学生心理健康诊断测验()》测评报告',
		        area: ['830px', '95%'],
		        shade: 0.8,
		        maxmin: true,
		        content: ['../perEvaluationResult/reportdemo.jsp?id='+checkdata.checkid,'yes'],
		        cancel: function(){ 
				}
		    });
	    	layer.full(index);
	    }
	    if(obj.event === 'result2'){
	    	var index = layer.open({
				type: 2, 
			    title: '心理健康诊断测验',
		        area: ['830px', '95%'],
		        shade: 0.8,
		        maxmin: true,
		        content: ['../perEvaluationResult/reportEPQ.jsp?id='+checkdata.checkid,'yes'],
		        cancel: function(){ 
				}
		    });
	    	layer.full(index);
	    }
    });
});